//
//  SendEmailView.m
//  HouseShow
//
//  Created by  on 12-1-1.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "SendEmailView.h"


@implementation SendEmailView
@synthesize m_CountBackGroundView;
@synthesize m_EmailImage;
-(void) setM_EmailImage:(UIImage *)f_EmailImage{
    [m_EmailImage release];
    m_EmailImage = nil;
    m_EmailImage = f_EmailImage;
    [m_EmailImage retain];
    
    p_MailView = [[MFMailComposeViewController alloc] init];
    p_MailView.mailComposeDelegate= self;
    [p_MailView setSubject:@"万科地产"];
    
    [p_MailView setEditing:YES];
    [p_MailView setMessageBody:@"Hi,\r\n   我在万科地产 for ipad 重发现了这张图片，想于你分享： \r\n= = = = = = = = = = = = = = = = = = = = = = =  \r\n 本文来自于：万科地产 for ipad \r\n 你可以访问我们的官方网站获取详情:www.123.com " isHTML:NO];
    
    NSData *imageData=UIImagePNGRepresentation(m_EmailImage);
    [p_MailView addAttachmentData:imageData mimeType:@"png"  fileName:@"myimg.png"];
    [self.view addSubview:p_MailView.view];
}

-(void)disppearself{
    UIAlertView* tSendOK = [[UIAlertView alloc] initWithTitle:@"提示" message:@"邮件发送成功" delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles: nil];
    [tSendOK show];
    [tSendOK release];
    [p_MailView resignFirstResponder];
    [m_CountBackGroundView removeFromSuperview];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.2];
    self.view.frame = CGRectMake(150, ScreenHeight, ScreenWidth-300, ScreenHeight);
    [UIView commitAnimations];
}

-(void) dealloc{
    [m_EmailImage release];
    [p_MailView release];
    [m_CountBackGroundView release];
    [super dealloc];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

#pragma -
#pragma MFMailComposeViewControllerDelegate
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
    if (result == MFMailComposeResultCancelled) {
        [self disppearself];
    }else if(result == MFMailComposeResultSent){
        [self disppearself];
    }else if(result == MFMailComposeResultFailed){
        [self disppearself];
    }
}

@end
